﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities;

namespace BouquetApplication
{
    public partial class BouquetForm : Form
    {
        private Bouquet bouquet = new Bouquet();

        public BouquetForm()
        {
            InitializeComponent();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            EditPlantForm form = new EditPlantForm();
            form.ShowDialog();

            AbstractPlant plant = form.Plant;
            if (plant != null)
            {
                bouquet.Add(plant);
            }
            Refref(bouquet);
        }

        private void deleteButton_Click(object sender, EventArgs e)
        {
            AbstractPlant selectedItem = (AbstractPlant)flowersListBox.SelectedItem;
            List<AbstractPlant> plants = bouquet.Plants;
            plants.Remove(selectedItem);
            Refref(bouquet);
        }

        private void Refref(Bouquet bouquet)
        {
            this.flowersListBox.Items.Clear();

            List<AbstractPlant> plants = bouquet.Plants;
            if (plants != null)
            {
                foreach (AbstractPlant plant in plants)
                {
                    flowersListBox.Items.Add(plant);
                }
            }
        }

    }
}
